<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>05员工表格练习</title>
</head>
<body>
<input type="text" id="name" placeholder="请输入员工姓名">
<input type="text" id="salary" placeholder="请输入员工工资">
<input type="text" id="job" placeholder="请输入员工岗位">
<button onclick="addEmp()">添加员工</button>
<hr>
<table border="1px">
    <caption>员工表</caption>
    <tr>
        <th>姓名</th>
        <th>工资</th>
        <th>岗位</th>
    </tr>
</table>

<script>
    let arr = [];
    function addEmp() {
        let nameId = document.getElementById('name').value;
        let salaryId = document.getElementById('salary').value;
        let jobId = document.getElementById('job').value;
        console.log(nameId,salaryId,jobId)

        let tableE = document.querySelector('table');
        console.log(tableE)
        let trE = document.createElement('tr');
        let nameTd = document.createElement('td');
        let salaryTd = document.createElement('td');
        let jobTd = document.createElement('td');

        nameTd.innerHTML = nameId
        salaryTd.innerHTML = salaryId
        jobTd.innerHTML = jobId
        console.log(trE,nameTd,salaryTd,jobTd)

        trE.append(nameTd, salaryTd, jobTd);
        tableE.append(trE);


        arr.push({name:nameId,salary:salaryId,job:jobId})
        console.log(arr)

        document.getElementById('name').value = '';
        document.getElementById('salary').value = '';
        document.getElementById('job').value = '';
    }

</script>

</body>
</html>